package com.kit.data.kitopeso.adapter;

import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.kit.data.kitopeso.R;
import com.kit.data.kitopeso.obj.KitoIdentity;
import com.kit.data.kitopeso.tools.ResUtils;

import java.util.List;

public class IdentityAdapter extends PagerAdapter {


    int index;

    private List<View> mList;

    List<KitoIdentity> dataList;


    public IdentityAdapter(List<View> mList, List<KitoIdentity> dataList) {
        this.mList = mList;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_NONE;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = mList.get(position);

        TextView tvTitle = view.findViewById(R.id.tvTitle);
        ImageView tvIcon = view.findViewById(R.id.tvIcon);

        KitoIdentity item = dataList.get(position);

        tvTitle.setText(item.getTitle());

        if (index == position) {
            tvTitle.setSelected(true);
            tvIcon.setImageResource(item.getIcon1());
            tvTitle.setTypeface(null, Typeface.BOLD);
            tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
        } else {
            tvTitle.setSelected(false);
            tvIcon.setImageResource(item.getIcon());
            tvTitle.setTypeface(null, Typeface.NORMAL);
            tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        }


        container.addView(view);
        return mList.get(position);
    }


    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
